const express = require('express');
const router = express.Router();
const user_handler = require('../router_handler/user');

// 验证规则
const expressJoi = require('@escook/express-joi');
const {
	updatePassword_schema,
	addUser_schema, 
	updateUser_schema, 
	regularization_schema, 
	leave_schema,
	getUserSalary_schema
} = require('../schema/user');

// 上传图片插件
const multer = require('multer');

// 头像
const uploadImage = multer({
	limits: {
		// 限制文件大小10M
		fileSize: 10000*1000,
		// 限制文件数量
		fils: 1
	},
	// 限制文件类型
	fileFilter: function(req, file, cb){
		if(file.mimetype == 'image/gif' || file.mimetype == 'image/png' || file.mimetype == 'image/jpeg'){
			cb(null, true)
		} else {
			cb(null, false)
		}
	},
	dest: 'static/img/'
});
// PDF文件
const uploadPdf = multer({
	limits: {
		// 限制文件大小100M
		fileSize: 100000*1000,
		// 限制文件数量
		fils: 1
	},
	// 限制文件类型
	fileFilter: function(req, file, cb){
		if(file.mimetype == 'application/pdf'){
			cb(null, true)
		} else {
			cb(null, false)
		}
	},
	dest: 'static/pdf/'
})

// 修改密码
router.post('/updatePassword', expressJoi(updatePassword_schema), user_handler.updatePassword);

//
// 上传头像
router.post('/addUserPhoto', uploadImage.single('user_photo'),user_handler.addUserPhoto)
// 新建用户
router.post('/addUser', expressJoi(addUser_schema), user_handler.addUser);
// 更新用户基本信息
router.post('/updateUser', expressJoi(updateUser_schema), user_handler.updateUser);
// 查询用户基本信息
router.get('/getUserList', user_handler.getUserList);
// 通过用户名查询用户列表
router.get('/getUserName', user_handler.getUserName);
// 通过id查询用户详细信息
router.get('/getUser', user_handler.getUser)

// 
// 添加保险
router.post('/addInsurance', user_handler.addInsurance);
// 查询保险
router.get('/getInsurance', user_handler.getInsurance);
// 删除保险
router.post('/deleteInsurance', user_handler.deleteInsurance);
// 更新保险
router.post('/updateInsurance', user_handler.updateInsurance);

//
// 上传合同
router.post('/addPdf',  uploadPdf.single('pdf'), user_handler.addPdf);
// 转正
router.post('/regularization', expressJoi(regularization_schema), user_handler.regularization);
// 离职
router.post('/leave', expressJoi(leave_schema),user_handler.leave);

//
// id查询工资条(未提交，已提交)
router.get('/getAllSalary', user_handler.getAllSalary);
// 保存
router.post('/saveSalary', user_handler.saveSalary);
// 提交
router.post('/submitSalary', user_handler.submitSalary);
// 查看工资条(已提交，已审核)
router.get('/getSubmitSalary', user_handler.getSubmitSalary);
// 通过
router.post('/agreeSalary', user_handler.agreeSalary);
// 查看个人历史工资记录
router.get('/getUserSalary',user_handler.getUserSalary);

// 获取选择框用户下拉列表
router.get('/getUserSelectList', user_handler.getUserSelectList)

// 获取徽标信息
router.get('/getReddot', user_handler.getReddot)

module.exports = router;